package loan.calc.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.GroupedOpenApi;
import org.springdoc.core.customizers.GlobalOpenApiCustomizer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootVersion;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



@Configuration
public class SwaggerConfig {

    @Value("${spring.application.name:UNKNOWN}")
    private String appName;

    @Bean
    public GroupedOpenApi groupedOpenApi(){
        String[] paths = { "/**" };
        return GroupedOpenApi.builder().group(appName)
                .pathsToMatch(paths)
                //.packagesToScan(new String[]{"loan.calc.**.controller"})
                .build();
    }

    @Bean
    public OpenAPI openApi() {
        return new OpenAPI()
                .info(new Info()
                        .title(appName + " RESTful APIs")
                        .version("Application Version: " + "1.0" + ";\r\n Spring Boot Version: " + SpringBootVersion.getVersion())
                        .description("# " + appName + " RESTful APIs")
                        // .termsOfService("http://example.com")
                        // .license(new License().name("Apache 2.0").url("http://doc.xiaominfo.com"))
                );
    }

}
